import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
public class ShadowEffect extends Canvas implements Runnable{
	private GraphicsMIDlet midlet;
	private int r1x, r1y;
	private double angle1 = Math.PI/2, angle2 = Math.PI*3/2;
	private long starttime = 0;
	private int x1 = getWidth()/2-getWidth()/24, y1 = getHeight()/2 + getWidth()/6 - getWidth()/24;
	private int x2 = getWidth()/2-getWidth()/24, y2 = getHeight()/2 - getWidth()/6 - getWidth()/24;
	private int radius = getWidth()/6;
	private boolean run = true;
	public ShadowEffect(GraphicsMIDlet midlet){
		this.midlet = midlet;
		r1x = (getWidth()/2)-5;
		r1y = (getHeight()/2)-5;	
		setFullScreenMode(true);	
	}
	public void paint(Graphics g){
		g.setColor(255,255,255);
		g.fillRect(0,0,getWidth(),getHeight());
		//Bat dau ve shadow
		//g.setColor(255,0,0);
		//g.fillRect(r1x,r1y,10,10);

		//Dong duoi la ve red green blue
		//g.fillArc(getWidth()/2-50,getHeight()/2-100,100,100, 0, 360);
		//g.setColor(0, 255, 0);
		//g.fillArc(getWidth()/2-75,getHeight()/2-50,100,100, 0, 360);
		//g.setColor(0, 0, 255);
		//g.fillArc(getWidth()/2-25,getHeight()/2-50,100,100, 0, 360);

		//Bat dau ve Taichi
		g.setColor(200, 200, 200);
		g.fillRect(0,0,getWidth(),getHeight());
		g.setColor(255, 255, 255);
		//g.drawArc(getWidth()/2-getWidth()/6*2, getHeight()/2 - getWidth()/6*2, getWidth()/3*2, getWidth()/3*2, 0, 360);
		g.fillArc(getWidth()/2-getWidth()/6*2, getHeight()/2 - getWidth()/6*2, getWidth()/3*2, getWidth()/3*2, 90, 180);		
		g.setColor(0, 0, 0);
		g.fillArc(getWidth()/2-getWidth()/6*2, getHeight()/2 - getWidth()/6*2, getWidth()/3*2, getWidth()/3*2, 270, 180);
		g.fillArc(getWidth()/2-getWidth()/6, getHeight()/2 - getWidth()/6*2, getWidth()/6*2, getWidth()/6*2, 90, 180);
		g.setColor(255, 255, 255);
		g.fillArc(getWidth()/2-getWidth()/6, getHeight()/2, getWidth()/6*2, getWidth()/6*2, 270, 180);
		g.setColor(230, 230, 230);		
		//g.fillArc(getWidth()/2-getWidth()/24, getHeight()/2 - getWidth()/6 - getWidth()/24, getWidth()/12, getWidth()/12, 0, 360);
		g.fillArc(x2 - getWidth()/24, y2 - getWidth()/24, getWidth()/12, getWidth()/12, 0, 360);
		g.setColor(20, 20, 20);
		//g.fillArc(getWidth()/2-getWidth()/24, getHeight()/2 + getWidth()/6 - getWidth()/24, getWidth()/12, getWidth()/12, 0, 360);
		g.fillArc(x1 - getWidth()/24, y1 - getWidth()/24, getWidth()/12, getWidth()/12, 0, 360);	
	}
	public void run(){	
	
		while(run){
			if(System.currentTimeMillis() - starttime >= 2){
				starttime = System.currentTimeMillis();
				angle1 = angle1 - 0.01;
            			x1 = (int)(getWidth()/2 + radius * Math.cos(angle1));
            			y1 = (int)( getHeight()/2 + radius * Math.sin(angle1));
				angle2 = angle2 - 0.01;
            			x2 = (int)(getWidth()/2 + radius * Math.cos(angle2));
            			y2 = (int)( getHeight()/2 + radius * Math.sin(angle2));
			}
			repaint();
		}

	}
	protected void showNotify() {
		new Thread(this).start();
	}
	protected void keyPressed(int keycode){
		if(keycode == this.KEY_NUM2){
			r1y--;
			if(r1y<0)
				r1y = 0;
		}
		if(keycode == this.KEY_NUM4){
			r1x--;
			if(r1x < 0)
				r1x = 0;
		}
		if(keycode == this.KEY_NUM6){
			r1x ++;
			if(r1x > getWidth()-10)
				r1x = getWidth()-10;
		}
		if(keycode == this.KEY_NUM8){
			r1y++;
			if(r1y > getHeight()-10)
				r1y = getHeight()-10;
		}
		if(keycode == this.KEY_NUM1){
			r1x --;
			r1y --;
			if(r1x < 0)
				r1x = 0;
			if(r1y<0)
				r1y = 0;
		}
		if(keycode == this.KEY_NUM3){
			r1x++;
			r1y --;
			if(r1x > getWidth()-10)
				r1x = getWidth()-10;
			if(r1y<0)
				r1y = 0;
		}
		if(keycode == this.KEY_NUM7){
			r1x--;
			r1y ++;
			if(r1x < 0)
				r1x = 0;
			if(r1y > getHeight()-10)
				r1y = getHeight()-10;
		}
		if(keycode == this.KEY_NUM9){
			r1x++;
			r1y++;
			if(r1x > getWidth()-10)
				r1x = getWidth()-10;
			if(r1y > getHeight()-10)
				r1y = getHeight()-10;
		}
		if(keycode == this.KEY_POUND)
			midlet.exit();
		repaint();
	}
	protected void keyRepeated(int keycode){
		if(keycode == this.KEY_NUM2){
			r1y -= 5;
			if(r1y<0)
				r1y = 0;
		}
		if(keycode == this.KEY_NUM4){
			r1x -= 5;
			if(r1x < 0)
				r1x = 0;
		}
		if(keycode == this.KEY_NUM6){
			r1x += 5;
			if(r1x > getWidth()-10)
				r1x = getWidth()-10;
		}
		if(keycode == this.KEY_NUM8){
			r1y +=5;
			if(r1y > getHeight()-10)
				r1y = getHeight()-10;
		}
		if(keycode == this.KEY_NUM1){
			r1x -=5;
			r1y -=5;
			if(r1x < 0)
				r1x = 0;
			if(r1y<0)
				r1y = 0;
		}
		if(keycode == this.KEY_NUM3){
			r1x+=5;
			r1y -=5;
			if(r1x > getWidth()-10)
				r1x = getWidth()-10;
			if(r1y<0)
				r1y = 0;
		}
		if(keycode == this.KEY_NUM7){
			r1x-=5;
			r1y +=5;
			if(r1x < 0)
				r1x = 0;
			if(r1y > getHeight()-10)
				r1y = getHeight()-10;
		}
		if(keycode == this.KEY_NUM9){
			r1x+=5;
			r1y+=5;
			if(r1x > getWidth()-10)
				r1x = getWidth()-10;
			if(r1y > getHeight()-10)
				r1y = getHeight()-10;
		}		
		repaint();
	}
	
}